<?php

namespace app\common\middleware;

use app\common\facade\Token;
use app\common\model\User;

class Auth
{
    public function handle($request, \Closure $next)
    {
        if(!env('AUTH_DEBUG',false)){
            if(Token::auth()){
                return $next($request);
            }
        }else{
            $user = User::find(env('AUTH_DEBUG_UID',null));
            $tokens = Token::encode($user);
            Token::set($tokens['token']);
            return $next($request);
        }
    }
}
